﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取验证码</title>
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <style>
        body {
            background-color: #f2f2f2;
            font-family: Arial, sans-serif;
        }

        .container {
            max-width: 400px;
            margin: 0 auto;
            padding: 40px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        h2 {
            text-align: center;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }

        input[type="text"],
        input[type="password"],
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }

        .btn {
            margin-bottom: 5px;
            display: block;
            width: 100%;
            padding: 10px;
            background-color: #4caf50;
            color: #fff;
            font-weight: bold;
            text-align: center;
            text-decoration: none;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

            .btn:hover {
                background-color: #45a049;
            }
    </style>
</head>
<body>
    <div class="container">
        <h2>小红书定向登录</h2>
        <div>
            <div class="form-group">
                <label for="phone">手机号码:</label>
                <input type="text" id="phone" name="phone" placeholder="输入手机号">
            </div>
            <div class="form-group">
                <label for="core">验证码:</label>
                <input type="text" id="core" name="core" placeholder="验证码">
            </div>
            <div class="form-group">
                <label>获取状态:</label>
                <textarea id="msg" disabled="disabled"></textarea>
            </div>
            <button class="btn" type="button" onclick="getCore()">获取</button>
            <button class="btn" type="button" style="background-color:red;" onclick="getCopy()">复制验证码</button>
        </div>
    </div>

    <script>
        //全局变量
        var iphone = "";
        $(document).ready(function () {
            iphone = "";
        });

        //树状图读取
        function getCore() {
            var token = "LcfnHR0PSQsGBFqbr9u+2p0cneqgRHGqlkRu3JcYwrDEWm/w65BkxGo4Ebd3LrjpxiQi0NaHicqoQLC5aKAqfSLcVbtzty7JtIsaVxwO3KXkUfo0Ut9OdehloYM2Qzl+p87CFH8PQEPAls6YrI8rXUpiB3UIrkbV5Pj1k5L6MIo";
            var project_id = "10100";
            var phone_num = $('#phone').val();
            var url = "http://api.sqhyw.net:90/api/get_message?token=" + token + "&project_id=" + project_id + "&phone_num=" + phone_num;
            if (phone_num == '' || phone_num.length != 11) {
                alert('请输入正确的手机号');
                return false;
            }
            $.ajax({
                url: url, // 请求的 URL
                type: 'GET', // 请求方法：GET、POST 等
                dataType: 'json', // 预期服务器返回的数据类型
                success: function (data, textStatus, jqXHR) {
                    if (data.message == 'ok') {
                        if (data.data.length == 0) {//获取失败
                            $('#core').val('');
                            $('#msg').val('尚未获取到验证码，请稍后重试');
                        } else {//获取成功
                            $('#core').val(data.code);
                            $('#msg').val(data.data[0].modle);
                        }
                    } else {
                        $('#msg').val('获取失败,稍后重新尝试');
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $('#msg').val('网络出现错误，还请重新链接网络');
                    // 请求失败时的回调函数
                    console.log("请求失败: ", textStatus, errorThrown);
                }
            });
        };

        function getCopy() {
            var str = $('#core').val();
            if (str != '') {
                var $temp = $('<input>');
                $('body').append($temp);
                $temp.val(str).select();
                document.execCommand('copy');
                $temp.remove();
                alert('复制成功！');
            }
        };

    </script>
</body>
</html>